package com.igeekhome.controller;

import com.igeekhome.pojo.DNetwork;
import com.igeekhome.pojo.SysRole;
import com.igeekhome.pojo.SysStaffEnclose;
import com.igeekhome.service.INetworkService;
import com.igeekhome.service.ISysRoleService;
import com.igeekhome.service.ISysStaffEncloseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 立以宁
 */
@RequestMapping("/page")
@Controller
public class SysStaffEncloseController {


    @Autowired
    private ISysStaffEncloseService sysStaffEncloseService;

    @Autowired
    private INetworkService networkService;

    @Autowired
    private ISysRoleService sysRoleService;

    /**
     * 员工维护
     */
    @RequestMapping("/empList")
    public String employeeList(){

        return "pages/data/employee/emp";
    }


    @RequestMapping("/addEmp")
    public String addEmployee(Model model){

        List<DNetwork> dNetworks = networkService.selectAll();
        List<SysRole> sysRoles = sysRoleService.selectAllRole();

        model.addAttribute("dNetworks",dNetworks);
        model.addAttribute("roleList",sysRoles);
        return "pages/data/employee/addEmp";
    }

    @RequestMapping("/updateEmp/{id}")
    public String updateEmployee(@PathVariable("id") Integer id, Model model){
        SysStaffEnclose sysStaffEnclose = sysStaffEncloseService.selectByPrimaryKey(id);
        List<DNetwork> dNetworks = networkService.selectAll();
        List<SysRole> sysRoles = sysRoleService.selectAllRole();

        model.addAttribute("roleList",sysRoles);
        model.addAttribute("sysStaffEnclose",sysStaffEnclose);
        model.addAttribute("dNetworks",dNetworks);
        return "pages/data/employee/addEmp";
    }



}
